package com.youcai.springboot_day08_swagger.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;


@Configuration
@EnableSwagger2
public class swaggerConfig {





    @Bean
    public Docket docket(Environment environment){
        //设置swagger的项目环境
        Profiles profiles = Profiles.of("dev");
        boolean flag = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).
                //关闭
                enable(flag).
                select().apis(RequestHandlerSelectors.
                //扫描指定包
                basePackage("com.youcai.springboot_day08_swagger.controller")).
                //过滤什么路径
                //paths(PathSelectors.ant("/kuang/**")).
                        build();
    }

    public ApiInfo apiInfo(){
        Contact contact = new Contact("ferver", "https://gitee.com/", "3361144574@qq.com");
        return new ApiInfo(
                "ferver",
                "轻易放弃，原地踏步",
                "1.0",
                "https://gitee.com/",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList()
        );

    }


}
